package com.hackcloud.shardingjdbc.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 模板的读取类
 *
 * @author Jiaju Zhuang
 */
@Slf4j
public class DocTemplateRead2Listener extends AnalysisEventListener<DocData> {
    private static final List<String> DOC_NODE = Arrays.asList("request", "response", "extInfo", "fileExtInfo");
    /**
     * 每隔5条存储数据库，实际使用中可以100条，然后清理list ，方便内存回收
     */
    private static final int BATCH_COUNT = 200;

    private Map<String, List<DocData>> propertyMap = new HashMap<>();

    private List<DocData> cachedDataList = new ArrayList<>();


    @Override
    public void invoke(DocData data, AnalysisContext context) {
        if (!StringUtils.isEmpty(data.getFieldSortNo())) {
            cachedDataList.add(data);
        }


    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        String key = "";
        List<DocData> docDataList = new ArrayList<>();
        String fileSortNo = "";
        for (int i = 0; i < cachedDataList.size(); i++) {
            DocData docData = cachedDataList.get(i);
            //这是根节点
            if (DOC_NODE.contains(docData.getFieldSortNo())) {
                fileSortNo = docData.getFieldSortNo();
            }
        }
    }

    public Map<String, List<DocData>> getPropertyMap() {
        return propertyMap;
    }

    public static void main(String[] args) {
        String no = "2";
        int indexOf = no.lastIndexOf(".");
        System.out.println(indexOf);
    }


}
